const {baseURL} = require('./env').prod

const isVip = 'lyb'

module.exports = {
  // isDomain
  request:function(url='',data={},method='GET',isDomain=true, header = "application/x-www-form-urlencoded"){
    
    if(isDomain){
      url = `${baseURL}/${isVip}/${url}`
    }else{
      url = `${baseURL}/${url}`
    }
// console.log(url);
// console.log(data);
    return new Promise((resolve,reject)=>{
      wx.showLoading({
        title: '拼命加载中...',
      })
      let token = ''
      if(wx.getStorageSync('token')) {
        token = wx.getStorageSync('token')
      }
      wx.request({
        url,
        method,
        data,
        header: {
           'Content-Type': header,
           'token' : token
        },
        success(res){
          wx.hideLoading()
          resolve(res.data)
        },
        fail(error){
          reject(error)
        }
      })

    })

  }
}